﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using VanTaiData;
using VanTaiProperty;
namespace VanTaiProperty
{
    public class clsControllertb_Roles :clsConnect
    {
        private clsConnect cls = new clsConnect();
        private DataTable dt;
        #region[Get-Data]
        public DataTable BindGridRoles()
        {
            return cls.BindGridData("sp_TM_Roles");
        }
        public DataTable BindGridRoles_Detail_Edit(int id)
        {
            return cls.LayDuLieuParameter("sp_TM_Roles_Detail_Edit", "@Id", id);
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertRoles(clsTMRolesProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("NameRoles", data.NameRoles);
            cls.ExecuteNonQuery("sp_TM_Roles_Insert");
            return true;
        }
        public bool UpdateRoles(clsTMRolesProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("RolesID", data.RolesID);
            cls.AddParameter("NameRoles", data.NameRoles);
            cls.ExecuteNonQuery("sp_TM_Roles_Update");
            return true;
        }
        public bool Check_Del_tb_Users(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TM_Roles_Check_Delete_TMUser", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool Check_Del_tb_UserPermiss(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TM_Roles_Check_Delete_TMUserPermiss", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool DeleteRoles(int id)
        {
            cls.Delete("sp_TM_Roles_Delete", "@RolesID", id);
            return true;
        }
        #endregion

        #region[Search]
        public DataTable Search(string keywords)
        {
            return cls.Search("sp_TM_Roles_Search", "@KEYWORDS", keywords);
        }
        #endregion
    }
}
